<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('楼宇列表')"/>
    <style type="text/css" rel="styleSheet" >
        div.error{
            color: red;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="buildingSearchParam">
                <div class="select-list">
                    <ul>
                        <li class="select-time">
                            <label>创建时间：</label>
                            <input type="text" class="time-input" placeholder="开始时间"
                                   name="params[beginCreateDatetime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" placeholder="结束时间" name="params[endCreateDatetime]"/>
                        </li>
                        <li class="select-time">
                            <label>更新时间：</label>
                            <input type="text" class="time-input" placeholder="开始时间"
                                   name="params[beginUpdateDatetime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" placeholder="结束时间" name="params[endUpdateDatetime]"/>
                        </li>
                        <li>
                            <label>创建人登录名：</label>
                            <input type="text" name="createBy"/>
                        </li>
                        <li>
                            <label>更新人登录名：</label>
                            <input type="text" name="updateBy"/>
                        </li>
                        <li>
                            <label>所属场所名称：</label>
                            <input type="text" name="sscsMc"/>
                        </li>
                        <li>
                            <label>所属场所类型：</label>
                            <select name="sscsLx" class="form-control m-b" th:with="type=${@dict.getType('b_zzslx')}" >
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>楼号：</label>
                            <input type="text" name="lh"/>
                        </li>
                        <!--<li>
                            <label>每栋拥有单元数：</label>
                            <input type="text" name="dys"/>
                        </li>-->
                        <li>
                            <label>层数：</label>
                            <input type="text" name="cs"/>
                        </li>
                        <li>
                            <label>每层拥有户数：</label>
                            <input type="text" name="hs"/>
                        </li>
                        <li>
                            <label class="control-label ">所属社区：</label>
                            <input autocomplete="off" class="form-control" type="text" name="sqName" onclick="selectDeptTree()" id="sqName">
                            <input type="text" style="display: none;" name="sqCode" id="sqCode" >
                            <script type="text/javascript">
                                /* 用户管理-修改-选择部门树 */
                                function selectDeptTree() {
                                    var deptId = $.common.isEmpty($("#treeId").val()) ? "100" : $("#treeId").val();
                                    var url = ctx + "system/dept/selectDeptTree/" + deptId;
                                    var options = {
                                        title: '选择社区',
                                        width: "380",
                                        url: url,
                                        callBack: doSubmit
                                    };
                                    $.modal.openOptions(options);
                                }
                                function doSubmit(index, layero){
                                    var tree = layero.find("iframe")[0].contentWindow.$._tree;
                                    if ($.tree.notAllowParents(tree)) {
                                        var body = layer.getChildFrame('body', index);
                                        $("#sqCode").val(body.find('#treeId').val());
                                        $("#sqName").val(body.find('#treeName').val());
                                        layer.close(index);
                                    }
                                }
                            </script>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="buildingSerch()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="place:building:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="place:building:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="buildingRemoveAll()"
               shiro:hasPermission="place:building:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="place:building:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var addFlag = [[${@permission.hasPermi('place:building:add')}]];
    var editFlag = [[${@permission.hasPermi('place:building:edit')}]];
    var removeFlag = [[${@permission.hasPermi('place:building:remove')}]];
    var sscsLxDatas = [[${@dict.getType('b_zzslx')}]];
    var prefix = ctx + "place/building";
    $("#buildingSearchParam").validate({
        focusCleanup: true,
        rules:{
            lh:{
                digits:true,
                min:0,
                max:254
            },
            cs:{
                digits:true,
                min:0,
                max:254
            },
            hs:{
                digits:true,
                min:0,
                max:254
            }
        },
        messages:{
            lh:"只能输入0-254之间的正整数",
            cs:"只能输入0-254之间的正整数",
            hs:"只能输入0-254之间的正整数"
        },
        errorElement:"div"
    })
    function buildingSerch() {
        if ($.validate.form()) {
            $.table.search()
        }

    }
    function buildingRemoveAll() {
        if(confirm("如果删除楼宇将会同步删所属于该楼的所有房间，确定继续？")){
            $.operate.removeAll();
        }
    };
    function buildingRemove(buildingId) {
        if(confirm("如果删除楼宇将会同步删所属于该楼的所有房间，确定继续？")){
            console.log(buildingId);
            $.operate.remove(buildingId);
        }
    }
    function addBrothers(id){
        table.set();
        $.modal.open("添加兄弟楼" + table.options.modalName, prefix+"/addBrothers/"+id);
    }

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "楼宇",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'createDatetime',
                    title: '创建时间'
                },
                {
                    field: 'updateDatetime',
                    title: '更新时间'
                },
                {
                    field: 'createBy',
                    title: '创建人id'
                },
                {
                    field: 'updateBy',
                    title: '更新人'
                },
                {
                    field: 'sscsMc',
                    title: '所属场所名称'
                },
                {
                    field: 'sscsLx',
                    title: '所属场所类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(sscsLxDatas, value);
                    }
                },
                {
                    field: 'lh',
                    title: '楼号'
                },
             /*   {
                    field: 'dys',
                    title: '每栋拥有单元数'
                },*/
                {
                    field: 'cs',
                    title: '总层数'
                },
                {
                    field: 'hs',
                    title: '每层拥有户数'
                },
                {
                    field: 'sqName',
                    title: '所属社区'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + addFlag + '" href="javascript:void(0)" title="就是属于同一场所的楼宇" onclick="addBrothers(\'' + row.id + '\')"><i class="fa fa-edit"></i>新增兄弟楼</a> ');
                        /*actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ')*/;
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="buildingRemove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
</script>
</body>
</html>